<?php

function campionidainviare(){
  global $wpdb;
  $query = "SELECT * FROM wp_campioni_users WHERE campione_inviato='0' ORDER BY id DESC";
  $domande = $wpdb->get_results($query,ARRAY_A);
  ?>
<script type="text/javascript" src="<?= TH_TEMPLATE_URL . '/js/jQuery.js'?>"></script>
<script type="text/javascript" src="<?= TH_TEMPLATE_URL . '/js/domanderisposte.js'?>"></script>
<table id="testerTable" style="text-align: center; border-spacing:5px;">
  <tr style="background-color:red;"> 
    <td><strong>Nome</strong></td>    
    <td><strong>Cognome</strong></td>    
    <td><strong>Codice Fiscale</strong></td>    
    <td><strong>Via</strong></td>    
    <td><strong>Civico</strong></td>    
    <td><strong>Città</strong></td>    
    <td><strong>Provincia</strong></td>    
    <td><strong>Cap</strong></td>    
    <td><strong>Campione inviato</strong></td>    
  </tr>
  <?
  $i=0;
  foreach($domande as $key => $value){?>
  <?
    if($i%2 == 0)
      echo "<tr style='background-color:#e5e5e5;'>";
    else
      echo "<tr>";
  ?>
    <?foreach($value as $key_i => $value_i){
      if(!in_array($key_i, array("id","username","email","domanda")))
        if($key_i != "campione_inviato")
          echo "<td>$value_i</td>";
        else
          if($value_i == "0") 
            echo "<td><input type='button' value='Clicca quì se il campione è stato inviato' onclick='segnaComeInviato(this,\"".$value['id']."\");' /></td>";
          else 
            echo "<td>SI</td>";
        }?>
      <?}?>
  </tr>
</table>
  <?
  }

function domandeinarrivo(){
  global $wpdb;
  $query = "SELECT * FROM wp_campioni_users ORDER BY id DESC LIMIT 0,99";
  $domande = $wpdb->get_results($query,ARRAY_A);
  ?>
<script type="text/javascript" src="<?= TH_TEMPLATE_URL . '/js/jQuery.js'?>"></script>
<script type="text/javascript" src="<?= TH_TEMPLATE_URL . '/js/domanderisposte.js'?>"></script>
<table id="testerTable" style="text-align: center; border-spacing:5px;">
  <tr style="background-color:red;">
    <td><strong>ID</strong></td>
    <td><strong>Username</strong></td>
    <td><strong>E-mail</strong></td>    
    <td><strong>Domanda</strong></td>    
  </tr>
  <?
  $i=0;
  foreach($domande as $key => $value){?>
  <?
    if($i%2 == 0)
      echo "<tr style='background-color:#e5e5e5;'>";
    else
      echo "<tr>";
  ?>
    <?foreach($value as $key_i => $value_i){?>
      <?if(in_array($key_i, array("id","username","email","domanda")))
          echo "<td>$value_i</td>";
        }?>
      <?}?>
  </tr>
</table>
  <?
  }

function campioninviati(){
  global $wpdb;
  $query = "SELECT * FROM wp_campioni_users WHERE campione_inviato='1' ORDER BY id DESC";
  $domande = $wpdb->get_results($query,ARRAY_A);
  ?>
<script type="text/javascript" src="<?= TH_TEMPLATE_URL . '/js/jQuery.js'?>"></script>
<script type="text/javascript" src="<?= TH_TEMPLATE_URL . '/js/domanderisposte.js'?>"></script>
  <table id="testerTable" style="text-align: center; border-spacing:5px;">
  <tr style="background-color:red;"> 
    <td><strong>Nome</strong></td>    
    <td><strong>Cognome</strong></td>    
    <td><strong>Codice Fiscale</strong></td>    
    <td><strong>Via</strong></td>    
    <td><strong>Civico</strong></td>    
    <td><strong>Città</strong></td>    
    <td><strong>Provincia</strong></td>    
    <td><strong>Cap</strong></td>    
    <td><strong>Campione inviato</strong></td>    
  </tr>
  <?
  $i=0;
  foreach($domande as $key => $value){?>
  <?
    if($i%2 == 0)
      echo "<tr style='background-color:#e5e5e5;'>";
    else
      echo "<tr>";
  ?>
    <?foreach($value as $key_i => $value_i){
      if(!in_array($key_i, array("id","username","email","domanda",'tipologia_campione')))
        if($key_i != "campione_inviato")
            echo "<td>$value_i</td>";
          else
            if($value_i == "0") 
              echo "<td onclick='segnaComeInviato();'>NO</td>";
            else 
              echo "<td>SI</td>";
          }?>
      <?}?>
  </tr>
</table>
<?}?>


<?function campioniprofessionisti(){
  global $wpdb;
  $query = "SELECT * FROM wp_campioni_users WHERE campione_inviato='0' && tipologia_campione <> 'NULL' ORDER BY id DESC";
  
  $domande = $wpdb->get_results($query,ARRAY_A);
  ?>
<script type="text/javascript" src="<?= TH_TEMPLATE_URL . '/js/jQuery.js'?>"></script>
<script type="text/javascript" src="<?= TH_TEMPLATE_URL . '/js/domanderisposte.js'?>"></script>
  <table id="testerTable" style="text-align: center; border-spacing:5px;">
  <tr style="background-color:red;"> 
    <td><strong>Nome</strong></td>    
    <td><strong>Cognome</strong></td>    
    <td><strong>Codice Fiscale</strong></td>    
    <td><strong>Via</strong></td>    
    <td><strong>Civico</strong></td>    
    <td><strong>Città</strong></td>    
    <td><strong>Provincia</strong></td>    
    <td><strong>Cap</strong></td>    
    <td><strong>Campione inviato</strong></td>
    <td><strong>Tipologia Campione</strong></td>
  </tr>
  <?
  $i=0;
  foreach($domande as $key => $value){?>
  <?
    if($i%2 == 0)
      echo "<tr style='background-color:#e5e5e5;'>";
    else
      echo "<tr>";
  ?>
    <?foreach($value as $key_i => $value_i){
      if(!in_array($key_i, array("id","username","email","domanda"))){
        if($key_i == "tipologia_campione"){
          switch ($value_i) {
            case "test":
              echo '<td>TEST</td>';
              break;
            case "gamma":
              echo '<td>GAMMA</td>';
              break;
            case "bustine":
              echo '<td>BUSTINE</td>';
              break;
            default:
              echo "<td>ERRORE</td>";
              break;
          }
        }
        if($key_i == "campione_inviato")  
          if($value_i == "0") 
              echo "<td><input type='button' value='Clicca quì se il campione è stato inviato' onclick='segnaComeInviato(this,\"".$value['id']."\");' /></td>";
            else 
              echo "<td>SI</td>";
        if($key_i != "campione_inviato" && $key_i != "tipologia_campione")
            echo "<td>$value_i</td>";
            
          }}?>
      <?}?>
  </tr>
  </table>
<?}?>